package time_consume;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.math.BigDecimal;

public class MapperDemo extends Mapper<LongWritable, Text, Text, BeanDemo> {
    Text text = new Text();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, BeanDemo>.Context context)
            throws IOException, InterruptedException {
        String str = value.toString();
        String[] strArr = str.split("\t");

        //获取数据
        //格式为：日志ID username 时间戳 消费金额
        String username = strArr[1];
        String time = strArr[2];
        String priceString = strArr[3];

        BigDecimal price = new BigDecimal(priceString);

        //设置传递的key
        text.set(username);
        //设置传递的value
        BeanDemo bean = new BeanDemo(time, price);
        //传递数据
        context.write(text, bean);
    }
}
